#include "particle.h"
#include "face.h"
#include "spring.h"

Particle::Particle(int _id) : id(_id){
    mass = 0.0;
    kd = 0.0;
    miC = 0.0;
    position = Vector3D(0.0, 0.0, 0.0);
    velocity = Vector3D(0.0, 0.0, 0.0);
    initialPosition = position;
    initialVelocity = velocity;
    color = Color(1.0, 1.0, 0.0, 1.0);
    selected = false;
}

Particle::Particle(int _id, const Vector3D &_p, const Color &_c) : id(_id), color(_c), position(_p){
    velocity = Vector3D(0.0, 0.0, 0.0);
    mass = 0.0;
    kd = 0.30;
    miC = 1.2;
    selected = false;
    initialPosition = position;
    initialVelocity = velocity;
}

Particle::Particle(int _id, double _kd, double _miC, const Vector3D &_p, const Color &_c) : id(_id), color(_c), kd(_kd), miC(_miC), position(_p){
    velocity = Vector3D(0.0, 0.0, 0.0);
    mass = 0.0;
    selected = false;
    initialPosition = position;
    initialVelocity = velocity;
}

Particle::Particle(int _id, double _kd, double _miC, double _m, const Vector3D &_p, const Color &_c) : id(_id), color(_c), mass(_m), kd(_kd), miC(_miC), position(_p){
    velocity = Vector3D(0.0, 0.0, 0.0);
    selected = false;
    initialPosition = position;
    initialVelocity = velocity;
}

Particle::~Particle(){
}

int Particle::getID() const{
    return id;
}

void Particle::reset(){
    position = initialPosition;
    velocity = initialVelocity;
}

Color Particle::getColor() const{
    if(selected) return Color(1,0,0,1);
	return color;
}

const Color &Particle::getActualColor() const{
	return color;
}

void Particle::setColor(const Color &_c){
	color = _c;
}

double Particle::getMass() const{
	return mass;
}

void Particle::setMass(double _m){
	mass = _m;
}

double Particle::getKd() const{
	return kd;
}

void Particle::setKd(double _kd){
	kd = _kd;
}

double Particle::getMiC() const{
	return miC;
}

void Particle::setMiC(double _miC){
	miC = _miC;
}

Vector3D Particle::getPosition() const{
	return position; //- du;
}

void Particle::setPosition(const Vector3D &_p){
	position = _p;
}

Vector3D Particle::getVelocity() const{
	return velocity;
}

void Particle::setVelocity(const Vector3D &_v){
	velocity = _v;
}

void Particle::move(const Vector3D &_p){
	position = _p;
}

double Particle::area() const{

    //descobre-se as molas horizontais que estão ligadas a particula, e soma seus comprimento de repouso
    //descobre-se as molas verticais que estão ligadas a particula, e soma seus comprimento de repouso
    //multiuplica os dois valores

    double vertical = 0;

    double horizontal = 0;

    for(unsigned int i = 0; i < springs.size(); i++)
    {
        Spring *s = springs[i];

        if(s->getType() == STRUCTURAL_HORIZONTAL)
            horizontal += s->getOriginalLength() / 2.0;
        else if(s->getType() == STRUCTURAL_VERTICAL)
            vertical += s->getOriginalLength() / 2.0;
    }

    return vertical * horizontal;
}
